import axios from "axios";
import config from "../config/Config.js";

const contentHttp={
    BASE_URL: config.BASE_URL + "/cms",
    /**
     * 保存内容信息
     * @param {*} content 
     * @param {*} callback 
     */
    save(content,callback){
        axios.post(this.BASE_URL + "/content/save",content)
        .then(res=>callback(res.data));
    },
    /**
     * 多条件的分页查询
     * @param {*} content 
     * @param {*} callback 
     */
    list(content,page=1,limit=10,callback){
        let url = this.BASE_URL + "/content/list?page=" + page + "&limit=" + limit;
        if(content){
            if(content.catId){
                url += "&catId=" + content.catId;
            }
            if(content.text1){
                url += "&text1=" + content.text1;
            }
            if(content.url){
                url += "&url=" + content.url;
            }
            if(content.status){
                url += "&status=" + content.status;
            }
        } 
        // 发送请求
        axios.get(url).then(res=>callback(res.data));
    }

}

export default contentHttp;